<?php

namespace App\Http\Controllers\Front;

use App\Http\Controllers\Controller;
use App\Services\Form\initFormData as InitFormData;
use Illuminate\Http\Request;

class Info extends Controller
{
    public function index(Request $request, InitFormData $formData)
    {
        $type = $request->input('type');
        $tabMenuType = $request->input('flag');
        $breadMenuList = config('front.bread_menu');

        switch ($type) {
            case parent::MENU_TANWIN_LIB:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_TANWIN_LIB];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::MENU_TANWIN_LIB, $tabMenuType);
                $typeFlag = 'tsa05';
                $paramList = ['附件'];
                $selectedMenu = parent::MENU_TANWIN_LIB;
                break;
            case parent::MENU_ASSET_COO:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_ASSET_COO];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::MENU_ASSET_COO, $tabMenuType);

                if ($tabMenuType == 1) {
                    $typeFlag = 'tsa07';
                    $paramList = ['项目合作模式', '融资额度', '融资期限', '融资成本'];
                } elseif ($tabMenuType == 2) {
                    $typeFlag = 'tsa06';
                    $paramList = ['领域', '融资主体', '融资方式', '融资期限'];
                }
                $selectedMenu = parent::MENU_ASSET_COO;

                break;
            case parent::TAB_MENU_INDUSTRY_COO_SOLUTION:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_SOLUTION];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::TAB_MENU_INDUSTRY_COO_SOLUTION, $tabMenuType);
                $typeFlag = 'tsa01';
                $paramList = ['领域', '典型案例', '适用条件'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_INDUSTRY_COO_EXPERT:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_EXPERT];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::TAB_MENU_INDUSTRY_COO_EXPERT, $tabMenuType);
                $typeFlag = 'tsa02';
                $paramList = ['地区', '职称', '单位', '简介', '项目经验', '学术成果'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_INDUSTRY_COO_CHAIN:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_CHAIN];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::TAB_MENU_INDUSTRY_COO_CHAIN, $tabMenuType);
                $typeFlag = 'tsa03';
                $paramList = ['技术路径'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_INDUSTRY_COO_GREEN_RESULT:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_GREEN_RESULT];
                $tabMenuInfo = '';
                $typeFlag = 'tsa08';
                $paramList = ['领域', '服务行业'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_MARKET_COO_TECH:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_MARKET_COO, parent::TAB_MENU_MARKET_COO_TECH];
                $tabMenuInfo = '';
                $typeFlag = 'tsa04';
                $paramList = [];
                $selectedMenu = parent::MENU_MARKET_COO;
                break;
            default:
                # code...
                break;
        }
        $result = $formData->getOtherInfo($request, $typeFlag, parent::CODE_INFO);
        $viewData = [
            'seo' => $this->returnSeoInfo('info'),
            'selectedMenu' => $selectedMenu,
            'breadMenuList' => $breadMenuList,
            'currentBreadMenuList' => $currentBreadMenuList,
            'tabMenuInfo' => $tabMenuInfo,
            'dataInfo' => $result['dataInfo'],
            'paramList' => $paramList,
            'typeFlag' => $typeFlag,
        ];
        return view('web.common.info', $viewData);
    }

    public function indexMobile(Request $request, InitFormData $formData)
    {
        $type = $request->input('type');
        $tabMenuType = $request->input('flag');
        $breadMenuList = config('front.bread_menu');

        switch ($type) {
            case parent::MENU_TANWIN_LIB:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_TANWIN_LIB];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::MENU_TANWIN_LIB, $tabMenuType);
                $typeFlag = 'tsa05';
                $paramList = ['附件'];
                $selectedMenu = parent::MENU_TANWIN_LIB;
                break;
            case parent::MENU_ASSET_COO:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_ASSET_COO];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::MENU_ASSET_COO, $tabMenuType);

                if ($tabMenuType == 1) {
                    $typeFlag = 'tsa07';
                    $paramList = ['项目合作模式', '融资额度', '融资期限', '融资成本'];
                } elseif ($tabMenuType == 2) {
                    $typeFlag = 'tsa06';
                    $paramList = ['领域', '融资主体', '融资方式', '融资期限'];
                }
                $selectedMenu = parent::MENU_ASSET_COO;

                break;
            case parent::TAB_MENU_INDUSTRY_COO_SOLUTION:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_SOLUTION];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::TAB_MENU_INDUSTRY_COO_SOLUTION, $tabMenuType);
                $typeFlag = 'tsa01';
                $paramList = ['领域', '典型案例', '适用条件'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_INDUSTRY_COO_EXPERT:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_EXPERT];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::TAB_MENU_INDUSTRY_COO_EXPERT, $tabMenuType);
                $typeFlag = 'tsa02';
                $paramList = ['地区', '职称', '单位', '简介', '项目经验', '学术成果'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_INDUSTRY_COO_CHAIN:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_CHAIN];
                $tabMenuInfo = $this->_getTabMenuInfo(parent::TAB_MENU_INDUSTRY_COO_CHAIN, $tabMenuType);
                $typeFlag = 'tsa03';
                $paramList = ['技术路径'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_INDUSTRY_COO_GREEN_RESULT:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_INDUSTRY_COO, parent::TAB_MENU_INDUSTRY_COO_GREEN_RESULT];
                $tabMenuInfo = '';
                $typeFlag = 'tsa08';
                $paramList = ['领域', '服务行业'];
                $selectedMenu = parent::MENU_INDUSTRY_COO;
                break;
            case parent::TAB_MENU_MARKET_COO_TECH:
                $currentBreadMenuList = [parent::MENU_INDEX, parent::MENU_MARKET_COO, parent::TAB_MENU_MARKET_COO_TECH];
                $tabMenuInfo = '';
                $typeFlag = 'tsa04';
                $paramList = [];
                $selectedMenu = parent::MENU_MARKET_COO;
                break;
            default:
                # code...
                break;
        }
        $result = $formData->getOtherInfo($request, $typeFlag, parent::CODE_INFO);
        $viewData = [
            'seo' => $this->returnSeoInfo('info'),
            'selectedMenu' => $selectedMenu,
            'breadMenuList' => $breadMenuList,
            'currentBreadMenuList' => $currentBreadMenuList,
            'tabMenuInfo' => $tabMenuInfo,
            'dataInfo' => $result['dataInfo'],
            'paramList' => $paramList,
            'typeFlag' => $typeFlag,
        ];
        return view('mobile.common.info', $viewData);
    }

    private function _getTabMenuInfo($menu, $tabMenuType)
    {
        $info = config('front.tab_menu.' . $menu);
        return [
            'url' => $info[$tabMenuType]['url'],
            'name' => $info[$tabMenuType]['name'],
        ];
    }
}
